package com.cwrl.spider.server.test.flow.price.node;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.cwrl.spider.server.test.flow.price.PriceContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;

import java.math.BigDecimal;

/**
 * @author cw
 */
@LiteflowComponent(value = "ticketNode", name = "优惠券节点")
public class TicketNodeComponent extends NodeComponent {
    @Override
    public void process() throws Exception {
        System.out.println("优惠券节点");
        PriceContext contextBean = this.getContextBean(PriceContext.class);
        if (CollUtil.isNotEmpty(contextBean.getList())) {
            String orderId = contextBean.getOrderId();
            contextBean.getList().forEach(
                    ticketId -> {
                        System.out.println("orderId:" + orderId + " ticketId:" + ticketId);
                        contextBean.setTotalPrice(NumberUtil.sub(contextBean.getTotalPrice(), new BigDecimal(ticketId)));
                    }
            );

        }
    }

    @Override
    public boolean isAccess() {
        return super.isAccess();
    }
}
